// 管理员管理用户接口
import {request} from '../utils/request'

const questionApi = {
  addUser: '/admin/create',
  verifyDelete: '/admin/verifyDelete',
  searchTeacher: '/admin/searchTeacher',
  searchStudent: '/admin/searchStudent',
  deleteTeacher: '/admin/deleteTeacher',
  deleteStudent: '/admin/deleteStudent',
  getKnowledgePoints: '/subject/getKnowledgePoints',
  findSubjectsByHouse: '/subject/findSubjectsByHouse',
  addKnowledgePoint: '/subject/addKnowledgePoint',
  addSubject: '/subject/addSubject',
  deleteKnowledgePointByID: '/subject/deleteKnowledgePointByID',
  deleteSubjectByID: '/subject/deleteSubjectByID',
  librarySearch: '/questionBank/liberary/search',
  verify: '/questionBank/verify',
  cancel: '/questionBank/cancel',
  completeInfo: '/userInfo/teacher/complete'
}

// 管理用户
// 身份验证
export function verifyDelete (pw) {
  return request({
    url: questionApi.verifyDelete,
    method: 'post',
    params: {
      account: pw
    }
  })
}
// 增加用户
export function addUser (userInfo) {
  return request({
    url: questionApi.addUser,
    method: 'post',
    params: {
      identity: userInfo.type
    },
    data: {
      account: userInfo.id,
      password: userInfo.password,
      house: userInfo.house
    }
  })
}
// 获取老师
export function searchTeacher (info) {
  return request({
    url: questionApi.searchTeacher,
    method: 'get',
    params: {
      index: info.index,
      page_size: info.pageSize
    }
  })
}
// 获取学生
export function searchStudent (info) {
  return request({
    url: questionApi.searchStudent,
    method: 'get',
    params: {
      index: info.index,
      page_size: info.pageSize
    }
  })
}
// 删除老师
export function deleteTeacher (number) {
  return request({
    url: questionApi.deleteTeacher,
    method: 'post',
    params: {
      teacherId: number
    }
  })
}
// 删除学生
export function deleteStudent (id) {
  return request({
    url: questionApi.deleteStudent,
    method: 'post',
    params: {
      studentId: id
    }
  })
}

// 获取本科目知识点
export function getKnowledgePoints (subjectId) {
  return request({
    url: questionApi.getKnowledgePoints,
    method: 'get',
    params: {
      'subjectId': subjectId
    }
  })
}

// 获取本学院科目
export function findSubjectsByHouse (houseName) {
  return request({
    url: questionApi.findSubjectsByHouse,
    method: 'get',
    params: {
      house: houseName
    }
  })
}

// 增加知识点
export function addKnowledgePoint (knowledgePointInfo) {
  return request({
    url: questionApi.addKnowledgePoint,
    method: 'post',
    data: {
      name: knowledgePointInfo.name,
      subjectId: knowledgePointInfo.subjectId
    }
  })
}

// 增加科目
export function addSubject (subjectInfo) {
  return request({
    url: questionApi.addSubject,
    method: 'post',
    data: {
      name: subjectInfo.name,
      house: subjectInfo.house
    }
  })
}

// 删除知识点
export function deleteKnowledgePointByID (knowledgePointId) {
  return request({
    url: questionApi.deleteKnowledgePointByID,
    method: 'delete',
    params: {
      id: knowledgePointId
    }
  })
}

// 删除知识点
export function deleteSubjectByID (subjectId) {
  return request({
    url: questionApi.deleteSubjectByID,
    method: 'delete',
    params: {
      id: subjectId
    }
  })
}

// 根据学院和状态查找题库
export function librarySearchAll (info) {
  return request({
    url: questionApi.librarySearch,
    method: 'get',
    params: {
      page_size: info.page_size,
      index: info.index,
      status: info.status
    }
  })
}

// 根据所属老师，状态、科目查询题库
export function librarySearch (parameters) {
  return request({
    url: questionApi.librarySearch,
    method: 'get',
    params: {
      index: parameters.index,
      page_size: parameters.page_size,
      subjectId: parameters.subjectId,
      status: parameters.status
    }
  })
}

// 管理员审核题库
export function verify (bankId) {
  return request({
    url: questionApi.verify,
    method: 'post',
    params: {
      bankId: bankId
    }
  })
}

// 管理员撤销题库
export function cancel (bankId) {
  return request({
    url: questionApi.cancel,
    method: 'post',
    params: {
      bankId: bankId
    }
  })
}

// 老师完善信息
export function completeInfo (params) {
  return request({
    url: questionApi.completeInfo,
    method: 'post',
    data: {
      name: params.name
    },
    params: {
      teacherNumber: params.teacherNumber
    }
  })
}
